package com.example.manpower.Server.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.manpower.Dto.SalartStats;
import com.example.manpower.Entity.Salary;
import com.example.manpower.Entity.User;
import com.example.manpower.Mapper.UserMapper;
import com.example.manpower.Server.SalaryService;
import com.example.manpower.Mapper.SalaryMapper;
import com.example.manpower.Util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author asus
* @description 针对表【salary】的数据库操作Service实现
* @createDate 2024-10-11 09:56:26
*/
@Service
public class SalaryServiceImpl extends ServiceImpl<SalaryMapper, Salary> implements SalaryService{
    @Autowired
    private SalaryMapper salaryMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public Result select(SalartStats salartStats) {
        int start=(salartStats.getPage()-1)*salartStats.getSize();
        salartStats.setStart(start);
        List<Salary> num=salaryMapper.selectList(null);
        int total=num.size();
        List<SalartStats> list = salaryMapper.select(salartStats);
        HashMap<String,Object> hashMap = new HashMap<>();
        hashMap.put("list",list);
        hashMap.put("total",total);
        return new Result(200,"查询成功",hashMap);
    }

    @Override
    public Result update(Salary salary) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",salary.getUserId());
        int num = salaryMapper.update(salary, queryWrapper);
        return new Result(200,"修改成功",num);
    }
}




